/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amuthu.expression.function.indicator;

import org.amuthu.DataStore;
import org.amuthu.expression.Expression;
import org.amuthu.parser.ExpressionVisitor;

/**
 *
 * @author prabhu
 */
public abstract class StochasticFunction extends BaseIndicatorFunction
{
   private int kFastPeriod;
   private int kSlowPeriod;

   public int getKfast()
   {
      return kFastPeriod;
   }

   public void setKfast(int kFastPeriod)
   {
      this.kFastPeriod = kFastPeriod;
   }

   public int getKslow()
   {
      return kSlowPeriod;
   }

   public void setKslow(int kSlowPeriod)
   {
      this.kSlowPeriod = kSlowPeriod;
   }

   @Override
   public boolean doUpdateParameters(DataStore dataStore, Expression[] arguments, ExpressionVisitor visitor)
   {
      if (arguments.length < 3)
      {
         return false;
      }

      kFastPeriod = (int) visitor.evaluate(arguments[0]);

      if (kFastPeriod < 0)
      {
         return false;
      }

      kSlowPeriod = (int) visitor.evaluate(arguments[1]);

      if (kSlowPeriod < 0)
      {
         return false;
      }

      int dSlowPeriod = (int) visitor.evaluate(arguments[2]);

      if (dSlowPeriod < 0)
      {
         return false;
      }

      int startOffset = (arguments.length > 3) ? (int) visitor.evaluate(arguments[3]) : 0;

      setPeriod(dSlowPeriod);
      setOffset(startOffset);

      return true;
   }
}
